package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @ClassName MouseDemo
 * @Description
 * @Author wangss
 * @date 2020.06.04 22:37
 * @Version 1.0
 */
public class MouseDemo2 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();
        an.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(an);

        HBox hBox = new HBox(10);

        Button b1 = new Button("button1");
        Button b2 = new Button("button2");

        hBox.getChildren().addAll(b1, b2);

        AnchorPane.setTopAnchor(hBox, 100d);
        AnchorPane.setLeftAnchor(hBox, 100d);
        an.getChildren().add(hBox);
        primaryStage.setScene(scene);
        primaryStage.setTitle("ImageViewDemo");
        primaryStage.setWidth(600d);
        primaryStage.setHeight(600d);
        primaryStage.setResizable(false);
        primaryStage.show();

        // 在面板上拖拽就会触发
//        b1.setOnMouseDragged(event -> System.out.println("setOnMouseDragged"));

        // 下边这两个需要配合使用，先检测是否要拖拽，检测到以后设置开始全部拖拽，setOnMouseDragOver才会开始执行，且在按钮上拖拽才会有效果
        b1.setOnDragDetected(event -> {
            b1.startFullDrag();
//            System.out.println("setOnDragDetected");
        });
        b1.setOnMouseDragOver(event -> {
//            System.out.println("setOnMouseDragOver");
        });


        b1.setOnMouseDragEntered(event -> {
            System.out.println("setOnMouseDragEntered");
        });

        b1.setOnMouseDragExited(event -> {
            System.out.println("setOnMouseDragExited");
        });

        b1.setOnMouseDragReleased(event -> {
            System.out.println("setOnMouseDragReleased");
            System.out.println("拖拽开始源头 = " + event.getGestureSource());
        });
    }
}
